var loadPageList = [];
var questionSaveStatus = {};
/**
 * 加载试题数据列表
 * @param obj
 */
function loadQuestionList(obj) {
    if(loadPageList.indexOf(obj.pageNo)==-1){
        loadPageList.push(obj.pageNo);
        $.ajax({
            url: baseloaction +'/mobile/uc/play/exercises/loadExercisesQuestionList',
            type:'post',
            dataType:'html',
            data:{
                'examRecordId':obj.examRecordId,
                'status':obj.status,
                'currentPage':obj.pageNo
            },
            success:function (html) {
                if(obj.pageNo==1){
                    $("#question-list-box").html(html);
                }else{
                    var pageEm = $("div[data-no='"+obj.pageNo+"']")[0];
                    $(html).insertBefore($(pageEm));
                    $(".temporary-box[data-no='"+obj.pageNo+"']").remove();
                }
                if($.isFunction(obj.callback)){
                    obj.callback();
                }
            },
            error:function (error) {
                $.toast('系统错误，试题数据加载失败');
            }
        });
    }else{
        if($.isFunction(obj.callback)){
            obj.callback();
        }
    }
}

/**
 * 加载答题卡
 * @param examRecordId
 * @param status
 */
function loadCard(examRecordId,status) {
    setTimeout(function () {
        $.ajax({
            url: baseloaction +'/mobile/uc/play/exercises/loadExercisersCard',
            type:'post',
            dataType:'html',
            data:{
                'examRecordId':examRecordId,
                'status':status
            },
            success:function (html) {
                $("#AnswerCard-popup-num-list").html(html);
                var cardList = $("#AnswerCard-popup-num-list aside.exam-option-bx");
                $.each(cardList,function (index,em) {
                    var id = $(em).data('id');
                    questionSaveStatus['qr'+id]={'id':id,'status':false};
                });
                //答题卡
                cArticleMenuFn();
            },
            error:function (error) {
                $.toast('系统错误，回答答题卡失败');
            }
        });
    },200);
}


/**
 * 更新保存后的数据
 * @param saveId
 * @param currentId
 */
function updateSaveData(saveId,currentId,callback) {
    if(currentId > 0){
        questionSaveStatus['qr'+currentId] = {'id':currentId,'status':true};
    }
    if(saveId > 0){
        questionSaveStatus['qr'+saveId] = {'id':saveId,'status':false};
    }
    if($.isFunction(callback)){
        callback();
    }
}

/**
 * 获取要保存的试题记录ID
 * @param currentId
 * @returns {number}
 */
function getSaveId(currentId) {
    var status = true;
    var saveId = 0;
    $.each(questionSaveStatus,function (index,obj) {
        if(obj.status==true && status==true && obj.id != currentId){
            saveId = obj.id;
            status = false;
        }
    });
    return saveId;
}